package chat.fragments;

import android.app.DialogFragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.BaseAdapter;
import android.widget.ListView;

import com.whu.zj.R;


/**
 * 所有用户的相关操作
 * 移动好友到分组
 * 或者，移动到群组
 * Created by 凯 on 2015/10/30.
 */
public class UserRelatedFragment extends DialogFragment {

    public static final String TAG_MOVEFRAGMENT = "moveFragment";

    View parent;

    View v_move;
    ListView lv_class;

    // 界面结构
    BaseAdapter classAdapter;

//    // 选择用户
//    FriendAdapter.FriendModel.ClassifyModel.UserModel model;
//
//    // 数据源，包括分组和好友
//    FriendAdapter.FriendModel friendModel;

    // 移动到群组
    View v_moveToGroup;

    // 拥有群组选择
    ListView lv_Group;

    // 拥有的群组界面数据源
//    OwnGroupAdapter ownGroupAdapter;

    // 删除好友
    View v_delete;

//    public void setModel(FriendAdapter.FriendModel.ClassifyModel.UserModel model) {
//        this.model = model;
//    }
//
//    public void setFriendModel(FriendAdapter.FriendModel friendModel) {
//        this.friendModel = friendModel;
//    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        getDialog().requestWindowFeature(Window.FEATURE_NO_TITLE);
        View view = inflater.inflate(R.layout.fragment_movefriend, null);

        parent = view;
        initview(view);
        return view;
    }

    View.OnClickListener itemClick = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (v == v_move) {
                // 初始化移动分组界面
//                lv_class = (ListView) parent.findViewById(R.id.id_lv_class);
//                classAdapter = new ClassAdapter();
//                ClassAdapter temp = (ClassAdapter) classAdapter;
//                temp.setFriendModel(friendModel);
//                lv_class.setAdapter(classAdapter);
//
//                lv_class.setOnItemClickListener(new AdapterView.OnItemClickListener() {
//                    @Override
//                    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
//                        ClassAdapter temp = (ClassAdapter) classAdapter;
//                        FriendAdapter.FriendModel.ClassifyModel tempClass = temp.getFriendModel().getClassifyModels().get(position);
//                        move(model, tempClass);
//                    }
//                });
//
//                v_delete.setVisibility(View.GONE);
//                v_moveToGroup.setVisibility(View.GONE);
//                lv_class.setVisibility(View.VISIBLE);
            } else if (v == v_moveToGroup) {
                // 初始化选择群组界面
//                lv_Group = (ListView) parent.findViewById(R.id.id_lv_Group);
//                ownGroupAdapter = new OwnGroupAdapter();
//                ownGroupAdapter.setGroupModel(GroupModel.share());
//                lv_Group.setAdapter(ownGroupAdapter);
//
//                lv_Group.setOnItemClickListener(new AdapterView.OnItemClickListener() {
//                    @Override
//                    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
//                        GroupModel.GroupWithUser groupWithUser = (GroupModel.GroupWithUser) view.getTag(R.id.id_groupInfo);
//                        movetoGroup(groupWithUser);
//                        UserRelatedFragment.this.dismiss();
//                    }
//                });
//
//                v_delete.setVisibility(View.GONE);
//                v_move.setVisibility(View.GONE);
//                lv_Group.setVisibility(View.VISIBLE);
            } else if (v == v_delete) {
//                String id = model.getUser().getId() + "";
//                DeleteFriend.Upload upload = new DeleteFriend.Upload();
//                upload.setUserId(id);
//                upload.setFromId(UserInfo.getUserID());
//                new DeleteFriend(null, upload).delete();


                UserRelatedFragment.this.dismiss();
            }

        }
    };

    // 移动到哪个群组
//    private void movetoGroup(GroupModel.GroupWithUser groupWithUser) {
////        new AddToGroup(null, new AddToGroup.Upload(model.getUser().getId(), groupWithUser.getGroup().get_id(),
////                model.getUser().getAccount(), groupWithUser.getGroup().getGroupName())).add();
//    }


    // 初始化界面
    private void initview(View view) {
        v_move = view.findViewById(R.id.id_v_move);
        v_move.setOnClickListener(itemClick);

        v_moveToGroup = view.findViewById(R.id.id_v_addToGroup);
        v_moveToGroup.setOnClickListener(itemClick);

        v_delete = view.findViewById(R.id.id_v_delete);
        v_delete.setOnClickListener(itemClick);
    }

    // 移动好友 到 分组
//    private void move(FriendAdapter.FriendModel.ClassifyModel.UserModel model, FriendAdapter.FriendModel.ClassifyModel tempClass) {
////        new MoveFriend(null, UserInfo.getUserName(), model.getUser().getAccount(), UserInfo.getUserID(), model.getUser().getId() + "", tempClass.getClassify().getId() + "",
////                tempClass.getClassify().getClassifyName(), model.getUser().getClassifyID() + "").move();
////        getDialog().dismiss();
//    }
}
